package com.service;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.NamingException;

import com.dao.*;
import com.moddel.*;


public class SelectNewsService {
	private int pageSize=0;
	private int pageNow=1;//需要从jsp页面传入
	private int pageCount=0;//由rowCount和pageSize计算而得
	private int rowCount=0;
	ArrayList<news> resultList=new ArrayList<news>();
	NewsDao nd=new NewsDao();
	/*
	 获取信息的方法
	 */
	public ArrayList<news> SelectNews(int pageNow,int pageSize) throws NamingException{	
		 try {
			 this.pageNow=pageNow;
			 this.pageSize=pageSize;
			 resultList=nd.selectAllNews(pageSize, pageNow);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 return resultList;
		
    }
	/*
	 获取总页数的方法
	 */
	public int  getPageCount(int pageSize) throws SQLException{
		rowCount=nd.getRowcount();
		if(rowCount%pageSize==0){
			pageCount=rowCount/pageSize;
		}	
		else {
			pageCount=rowCount/pageSize+1;
		}
	    return pageCount;
		
	    } 
	public int  getRowCount() throws SQLException{
		rowCount=nd.getRowcount();
		return rowCount;
		
	}
	public boolean ifLogin(String username,String passwd){
		 boolean ifSucceed=false;
		 NewsDao nDao=new NewsDao();
		 int id1=nDao.login_1(passwd);
		 int id2=nDao.login_2(username);
		 if((id1==id2)&&(id1!=0)){
			 ifSucceed=true;
		 }
		 return ifSucceed;
	
	 }
	public boolean insertUserInfor(userBm ubm){
		NewsDao insertUserDao=new NewsDao();
		int ifSucceedInt=insertUserDao.insertIntoUser(ubm);
		boolean ifS;
		if(ifSucceedInt==1)
			ifS=true;
		else {
			ifS=false;
		}
		return ifS;
	}
}
